package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbGoodsMapper;
import com.dongdongshop.model.TbGoods;
import com.dongdongshop.model.TbGoodsExample;
import com.dongdongshop.service.GoodsService;
import com.dongdongshop.vo.GoodsVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private TbGoodsMapper tgm;

    @Override
    public List<GoodsVO> selectListByName() {
        List<TbGoods> goodsList = tgm.selectByExample(null);
        List<GoodsVO> voList = goodsList.stream().map(tbGoods -> {
            GoodsVO vo = new GoodsVO();
            BeanUtils.copyProperties(tbGoods, vo);
            return vo;
        }).collect(Collectors.toList());
        return voList;
    }

    @Override
    public void updateStatus1(Long[] ids) {
        TbGoodsExample example = new TbGoodsExample();
        example.createCriteria().andIdIn(Arrays.asList(ids));
        List<TbGoods> goodsList = tgm.selectByExample(example);
        for (TbGoods goods : goodsList) {
            goods.setAuditStatus("1");
            tgm.updateByPrimaryKeySelective(goods);
        }
    }

    @Override
    public void updateStatus2(Long[] ids) {
        TbGoodsExample example = new TbGoodsExample();
        example.createCriteria().andIdIn(Arrays.asList(ids));
        List<TbGoods> goodsList = tgm.selectByExample(example);
        for (TbGoods goods : goodsList) {
            goods.setAuditStatus("2");
            tgm.updateByPrimaryKeySelective(goods);
        }
    }

    //商品表的增加
    @Override
    public void addGoods(GoodsVO goodsVO) {

    }
}
